<?php	require_once(dirname(__FILE__).'/inc/config.inc.php');IsModelPriv('fang');



/*

**************************

(C)2010-2015 phpMyWind.com

update: 2014-5-30 17:03:29

person: Feng

**************************

*/





//初始化参数

$tbname = '#@__fang';

$gourl  = 'fang.php';

$action = isset($action) ? $action : '';





//添加列表信息

if($action == 'add')

{

	$lpid=isset($lpid) ? $lpid : "-1"; //楼盘id

	if($lpid=='-1'){

		exit;

	}

	//获取楼盘所在区域

	$r = $dosql->GetOne("SELECT id,areaid FROM `#@__loupan` WHERE `id`='$lpid'");

	if(isset($r['id']))

	{

		$areaid=$r['areaid'];

	}else{

		$areaid="";

	}

	

	$hxid=isset($hxid) ? $hxid : "-1"; //楼盘id

	if($hxid=='-1'){

		exit;

	}

	//获取户型数据

	$jsid="";

	//$mianji="";

	$junjia="";

	//$zongjia="";

	

	$r = $dosql->GetOne("SELECT * FROM `#@__huxing` WHERE `id`='$hxid'");

	if(isset($r['id']))

	{

		$jsid=$r['jsid'];

		//$mianji=$r['mianji'];

		//$zongjia=$r['zongjia'];

		$picurl=$r['picurl'];

	}

	

	

	$title=$louhao.'H-'.$danyuan.'D-'.$louceng.'C-'.$fanghao;

	$posttime = GetMkTime($posttime);









	$sql = "INSERT INTO `$tbname` ( title, areaid, lpid, jsid, hxid, louhao, danyuan, louceng, fanghao, mianji, junjia,zongjia,picurl,is_sale,orderid, posttime, checkinfo,author) VALUES ( '$title', '$areaid', '$lpid', '$jsid', '$hxid', '$louhao', '$danyuan', '$louceng', '$fanghao', '$mianji', '$junjia', '$zongjia', '$picurl','$is_sale', '$orderid', '$posttime', '$checkinfo' ,'$author')";

	if($dosql->ExecNoneQuery($sql))

	{

		header("location:$gourl");

		exit();

	}

}







//添加列表信息

if($action == 'add_all')

{

	$lpid=isset($lpid) ? $lpid : "-1"; //楼盘id

	if($lpid=='-1'){

		exit;

	}

	$num=isset($num) ? $num : "0"; // 楼层房间总数

	if($lpid=='0'){

		exit;

	}

	



	//获取楼盘所在区域

	$r = $dosql->GetOne("SELECT id,areaid FROM `#@__loupan` WHERE `id`='$lpid'");

	if(isset($r['id']))

	{

		$areaid=$r['areaid'];

	}else{

		$areaid="";

	}

	

	

	$posttime = GetMkTime($posttime);

	$dosql->Execute("SELECT * FROM `#@__huxing` WHERE `lpid`='$lpid' AND delstate='' AND checkinfo=true ",8);

	$huxing_arr=array();

	  while($row = $dosql->GetArray(8))

	  {

			$idd=$row['id'];

			$huxing_arr[$idd]=$row;

	  }

	

	for($k=1;$k<=$ceng;$k++){

		for($i=1;$i<=$num;$i++){

				$huxing_id=$hxid[$i];

				if($huxing_id=='-1'){

					exit;

				 }

				$jsid			=$huxing_arr[$huxing_id]['jsid'];

				$mianji	=$huxing_arr[$huxing_id]['mianji'];

				$zongjia	=$huxing_arr[$huxing_id]['zongjia'];

				$junjia		=$huxing_arr[$huxing_id]['junjia'];

				$picurl		=$huxing_arr[$huxing_id]['picurl'];

				$title		=$louhao.'H-'.$danyuan.'D-'.$k.'C-'.$i;

	$sql = "INSERT INTO `$tbname` ( title, areaid, lpid, jsid, hxid, louhao, danyuan, louceng, fanghao, mianji, junjia,zongjia,picurl,is_sale,orderid, posttime, checkinfo,author) VALUES ( '$title', '$areaid', '$lpid', '$jsid', '$huxing_id', '$louhao', '$danyuan', '$k', '$i', '$mianji', '$junjia', '$zongjia', '$picurl','$is_sale', '$orderid', '$posttime', '$checkinfo' ,'$author')";

				$dosql->ExecNoneQuery($sql);

				}

				

		}

		header("location:$gourl");

}







//修改列表信息

else if($action == 'update')

{



	$lpid=isset($lpid) ? $lpid : "-1"; //楼盘id

	if($lpid=='-1'){

		exit;

	}

	//获取楼盘所在区域

	$r = $dosql->GetOne("SELECT id,areaid FROM `#@__loupan` WHERE `id`='$lpid'");

	if(isset($r['id']))

	{

		$areaid=$r['areaid'];

	}else{

		$areaid="";

	}

	

	$hxid=isset($hxid) ? $hxid : "-1"; //楼盘id

	if($hxid=='-1'){

		exit;

	}

	//获取户型数据

	$jsid="";

	//$mianji="";

	$junjia="";

	//$zongjia="";

	

	$r = $dosql->GetOne("SELECT * FROM `#@__huxing` WHERE `id`='$hxid'");

	if(isset($r['id']))

	{

		$jsid=$r['jsid'];

		//$mianji=$r['mianji'];

		//$zongjia=$r['zongjia'];

		$picurl=$r['picurl'];

	}





	$posttime = GetMkTime($posttime);







	//  title, areaid, lpid, jsid, hxid, louhao, danyuan, louceng, fanghao, mianji, junjia,zongjia,picurl,is_sale,orderid, posttime, checkinfo,author

	$sql = "UPDATE `$tbname` SET title='$title', areaid='$areaid', lpid='$lpid', jsid='$jsid', louhao='$louhao', danyuan='$danyuan', louceng='$louceng', fanghao='$fanghao', mianji='$mianji', junjia='$junjia', zongjia='$zongjia', picurl='$picurl', is_sale='$is_sale', orderid='$orderid', posttime='$posttime', checkinfo='$checkinfo', author='$author' WHERE id=$id";

	if($dosql->ExecNoneQuery($sql))

	{

		header("location:$gourl");

		exit();

	}

}





//修改审核状态

else if($action == 'check')

{



	if($checkinfo == '已审')

	{

		$dosql->ExecNoneQuery("UPDATE `$tbname` SET `checkinfo`='false' WHERE `id`=$id");

		echo '<a href="javascript:;" onclick="CheckInfo('.$id.',\'未审\')" title="点击进行审核与未审操作">未审</a>';

		exit();

	}



	if($checkinfo == '未审')

	{

		$dosql->ExecNoneQuery("UPDATE `$tbname` SET `checkinfo`='true' WHERE `id`=$id");

		echo '<a href="javascript:;" onclick="CheckInfo('.$id.',\'已审\')" title="点击进行审核与未审操作">已审</a>';

		exit();

	}

}







//修改审核状态

else if($action == 'saleout')

{
	$fangtitle="";
	$lpid="";
	$r = $dosql->GetOne("SELECT * FROM `#@__fang` WHERE `id`='$id'");
	if(isset($r['id']))
	{
		$fangtitle=$r['title'];
		$lpid=$r['lpid'];
	}
	$loginip = GetIP();

	if($checkinfo == '已售')
	{
		$dosql->ExecNoneQuery("UPDATE `$tbname` SET `is_sale`='false' WHERE `id`=$id");
		$time=time();
		$sql2="insert into `#@__sale_log`  (lpid,fangid,fangtitle,admin,saletype,saletime,ip) values ('$lpid','$id','$fangtitle','$cfg_admin','在售','$time','$loginip')";
		$dosql->ExecNoneQuery($sql2);
		echo '<a href="javascript:;" class="btn btn-success" onclick="SaleOut('.$id.',\'在售\')" title="点击进行审核与未审操作">在售</a>';
		exit();
	}



	if($checkinfo == '在售')

	{

		$dosql->ExecNoneQuery("UPDATE `$tbname` SET `is_sale`='true' WHERE `id`=$id");
		$time=time();
		$sql2="insert into `#@__sale_log`  (lpid,fangid,fangtitle,admin,saletype,saletime,ip) values ('$lpid','$id','$fangtitle','$cfg_admin','已售','$time','$loginip')";
		$dosql->ExecNoneQuery($sql2);
		echo '<a href="javascript:;"  class="btn btn-danger" onclick="SaleOut('.$id.',\'已售\')" title="点击进行审核与未审操作">已售</a>';

		exit();

	}

}



//无状态返回

else

{

	header("location:$gourl");

	exit();

}

?>

